package com.example.blog.common;

import com.example.blog.model.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author YJ
 * @Date 2023/9/6 20:58
 * Description:Session工具类
 */
public class SessionUtil {
    /**
     * 获取当前用户
     *
     * @param request
     * @return
     */
    public static UserInfo getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if ( session != null && session.getAttribute(AppVariable.SESSION_USER_KEY) != null){
            //登录状态
            return (UserInfo) session.getAttribute(AppVariable.SESSION_USER_KEY);
        }
        return null;
    }
}
